<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title></title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1">
    <!-- 注意：项目正式环境请勿引用该地址 -->
    <link href="layui/css/layui.css" rel="stylesheet">
</head>
<body>


<script type="text/html" id="toolbarDemo">
        <button class="layui-btn layui-btn-sm" lay-event="insert" id="addSecurity"><i
                class="layui-icon">&#xe654;</i>新增
        </button>
        <button class="layui-btn layui-btn-sm" lay-event="deleteAll">批量删除</button>
        <div class="layui-inline" style="float:right;height:29px;" title="搜索" lay-event="search"><i
                class="layui-icon layui-icon-search"></i></div>
        <div class="layui-inline layui-show-xs-block">
        <select name="securityType" id="securityType" style="width:200px;float:right;height:30px;">
            <option placeholder="请选择" ></option>
            <option value="2">债券</option>
            <option value="1">股票</option>
        </select>
        </div>

        <input type="text" id="securityName"  style="width:200px;float:right;height:30px;" placeholder="请输入证券名称" autocomplete="off" class="layui-input">

</script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs" lay-event="edit">编辑</a>
    <a class="layui-btn layui-btn-danger layui-btn-xs" lay-event="del">删除</a>
</script>


<!-- 注意：项目正式环境请勿引用该地址 -->
<script src="layui/layui.js"></script>
<script type="text/javascript" src="layui/tableSelect.js"></script>


<script>
    layui.use(['table','tableSelect'], function () {
        var table = layui.table;
        var form = layui.form;
        var $ = layui.jquery;
        var layer = layui.layer;
        var tableSelect = layui.tableSelect
        //温馨提示：默认由前端自动合计当前行数据。从 layui 2.5.6 开始： 若接口直接返回了合计行数据，则优先读取接口合计行数据。
        //详见：/docs/modules/table.html#totalRow
        table.render({
            height: 'full-55'
            , minLength: "80",
            elem: '#myTable'
            , id: 'myTable'
            , url: 'selectSecurity'
            , toolbar: '#toolbarDemo'
            , page: true
            , limit: [5,10,15]
            , title: '用户数据表'
            , cols: [[
                 {type: 'checkbox', fixed: 'left'}
                ,{field: 'securityId', title: 'ID', fixed: 'left'}
                ,{field: 'securityName', title: '证券名称'}
                ,{field: 'releaseDate', title: '发行日期'}
                ,{field: 'delayDate', title: '延迟日期'}
                ,{field: 'security', title: '证券类型'}
                ,{field: 'exchange', title: '交易所'}
                ,{ title: '操作', toolbar: '#barDemo'}
            ]]
        });


        //工具栏事件
        table.on('toolbar(myTable)', function (obj) {
            var checkStatus = table.checkStatus(obj.config.id);
            switch (obj.event) {
                case 'getCheckData':
                    var data = checkStatus.data;
                    layer.alert(JSON.stringify(data));
                    break;
                case 'getCheckLength':
                    var data = checkStatus.data;
                    layer.msg('选中了：' + data.length + ' 个');
                    break;
                case 'isAll':
                    layer.msg(checkStatus.isAll ? '全选' : '未全选')
                    break;
            };

            if (obj.event == 'insert') {
                //点击按钮的时候，弹出一个添加页面
                layer.open({
                    type: 2,
                    title: "添加证券",
                    content: "addSecurity",
                    area: ['800px', '500px'],
                    //层销毁后触发
                    end: function () {
                           //刷新页面
                        table.reload('tableId');
                    }
                })
            };
            if(obj.event=='search'){
                var securityName=$("#securityName").val();
                var securityType = $("#securityType").val();
                //表格的重新加载事件
                table.reload('myTable', {
                    method: 'post'
                    , where: {
                        'securityName': securityName,
                        'securityType': securityType,
                    }
                    , page: {
                        curr: 1
                    }
                });
            }
        });

        table.on('tool(myTable)', function (obj) {
            switch (obj.event) {
                case"edit":
                    layer.open({
                        type:2,
                        title:'修改员工',
                        content:"updateSecurity",
                        area:['800px','400px'],
                        closeBtn:1,
                        success:function (layero,index) {
                            var body = layer.getChildFrame('body',index);
                            body.find("#securityId").val(obj.data.securityId);
                            body.find("#securityName").val(obj.data.securityName);
                            body.find("#releaseDate").val(obj.data.releaseDate);
                            body.find("#delayDate").val(obj.data.delayDate);
                            body.find("#securityType").val(obj.data.securityType);
                            body.find("#exchangeName").val(obj.data.exchangeName);
                        }
                    });
                    break;
                case "del":
                    layer.confirm('您确定要删除吗', function (index) {
                        $.getJSON("deleteSecurity"
                            , {securityId: obj.data.securityId}
                            , function (msg) {
                                if (msg == 1) {
                                    layer.close(index)
                                    table.reload('tableId');
                                }
                            })
                    })
                    break;
            }
        })
    });
</script>
<table  id="myTable" lay-filter="myTable" ></table>
</body>
</html>